<template>
    <div class="mineheader">
<!--        <router-link :to="{path:'/login'}">-->
            <div class="user">
                <router-link  :to="{path:'/pwdlogin'}"  v-if="$store.state.isLogin">
                    <van-icon name="manager"  style="font-size: 40px; color: aqua;"/>
                </router-link>
<!--                <van-icon name="manager"  style="font-size: 40px; color: aqua;" v-if="$store.state.isLogin"/>-->
                <van-image  v-else
                        round
                        width="10rem"
                        height="10rem"
                        :src="$store.state.userInfo.avatar"
                            class="imguser"
                />
            </div>
<!--        </router-link>-->
        <h2 v-if="$store.state.isLogin" style="margin-left: 100px">请先登录</h2>
        <div class="btnbox" v-else>
            <van-button type="default" class="btn">私信</van-button>
            <van-button type="default" class="btn" @click="concern" v-if="isConcern">关注</van-button>
            <van-button type="default" class="errbtn" @click="errconcern" v-else>已关注</van-button>
        </div>
        <div style="clear: both"></div>
        <h3  v-if="!$store.state.isLogin">{{$store.state.userInfo.userName}}</h3>
        <p @click="getInfo" v-if="!$store.state.isLogin">个人主页<van-icon name="arrow" /></p>
        <div class="userfooter">
            <van-row type="flex" justify="center">
                <van-col span="6">
                    <p style="text-align: center">0</p>
                    <p style="text-align: center">关注</p>
                </van-col>
                <van-col span="6">
                    <p style="text-align: center">0</p>
                    <p style="text-align: center">粉丝</p>
                </van-col>
                <van-col span="6">
                    <p style="text-align: center">0</p>
                    <p style="text-align: center">获赞</p>
                </van-col>
                <van-col span="6">
                    <p style="text-align: center">0</p>
                    <p style="text-align: center">圈子</p>
                </van-col>

            </van-row>
        </div>

    </div>
    
</template>

<script>
    import {getinformain} from "../api/api";

    export default {
        name: "mineHead",
        data(){
            return{
                isConcern:true,
                userName:'',
                avatar:'',
            }
        },
        methods:{
            concern(){
                this.isConcern=false;
            },
            errconcern(){
                this.isConcern=true;
            },
            getInfo(){
                this.$router.push('/info')
            }
        },
        created() {
            getinformain().then(res=>{
                console.log(res)
                if(res.data.code==0){
                    this.$store.commit("changeUserInfo",{userInfo:res.data.data})
                    // this.userName = this.$store.state.userInfo.userName
                    // this.avatar = this.$store.state.userInfo.avatar

                    if(this.$store.state.userInfo.sex == 1){
                        this.sex =  "男"
                    }else{
                        this.sex =  "女"
                    }

                }
            })
        }
    }
</script>

<style scoped>
    .mineheader {
        position: relative;
        width: 90%;
        height: 200px;
        background-color: white;
        border-radius: 12px;
    }
    .user {
        position: absolute;
        width: 70px;
        height: 70px;
        border-radius: 50%;
        background-color: aliceblue;
        left:20px;
        top:-20px;
        text-align: center;
        line-height: 80px;
    }
    /deep/.imguser {
        width: 70px !important;
        height: 70px !important;
    }
    .btnbox {
        margin: 10px 10px;
        float: right;
    }
    .btnbox>.btn {
        width: 80px;
        height: 30px;
        margin-left: 8px;
        border-radius: 5px;
        color: blue;
    }
    .btnbox>.errbtn {
        width: 80px;
        height: 30px;
        border-radius: 5px;
        margin-left: 8px;
        background-color: rgba(128, 128, 128, 0.3);
        color: gray;
    }
    .mineheader>h3 {
        margin: 0;
        /*margin-top: 10px;*/
        padding-left: 30px;
    }
    .mineheader>p {
        margin: 0;
        margin-top: 10px;
        padding-left: 30px;
        font-size: 15px;
    }
    .userfooter {
        margin-top: 20px;
    }
    .userfooter p {
        margin: 0;
    }
</style>